package client

import (
	"context"
	"github.com/sirupsen/logrus"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"latencyPublisher/api/pb"
	"net"
)

// NewNodeTopoNetMetricServiceClient 创建指向target的grpc客户端，此连接硬编码使用tcp连接
func NewNodeTopoNetMetricServiceClient(target string) (pb.NodeTopoNetMetricServiceClient, error) {
	dial, err := grpc.Dial(
		target,
		grpc.WithTransportCredentials(insecure.NewCredentials()),
		grpc.WithContextDialer(func(ctx context.Context, addr string) (conn net.Conn, e error) {
			return net.Dial("tcp", addr)
		}),
	)
	if err != nil {
		logrus.Errorf("[NewNodeTopoNetMetricServiceClient]-grpc.Dial出错, target=%s, err=%s", target, err)
		return nil, err
	}
	client := pb.NewNodeTopoNetMetricServiceClient(dial)
	return client, nil
}
